import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';

class AppInfoHeader extends StatelessWidget {
  const AppInfoHeader({super.key});

  @override
  Widget build(BuildContext context) {
    return const SizedBox(
      height: 300,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          _AppLogo(),
          SizedBox(height: 10,),
          _AppName(),
          _AppVersion(),
        ],
      ),
    );
  }
}

class _AppLogo extends StatelessWidget {
  const _AppLogo({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 110,
      decoration: BoxDecoration(
          boxShadow: [
            BoxShadow(
                color: Colors.lightBlue.shade100,
                blurRadius: 15,
                spreadRadius: 2
            )
          ]
      ),
      child: Image.asset("assets/images/app_icon.ico"),
    );
  }
}

class _AppName extends StatelessWidget {
  const _AppName({super.key});

  @override
  Widget build(BuildContext context) {
    return const Text("单词靶场",style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold));
  }
}

class _AppVersion extends StatefulWidget {
  const _AppVersion({super.key});

  @override
  State<_AppVersion> createState() => _AppVersionState();
}

class _AppVersionState extends State<_AppVersion> {
  String _version = "0.0.0"; // 默认版本号

  @override
  void initState() {
    super.initState();
    _getVersion();
  }

  void _getVersion() async {
    final packageInfo = await PackageInfo.fromPlatform();
    setState(() {
      _version = packageInfo.version;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Text("V${_version}",style: const TextStyle(fontSize: 15,fontWeight: FontWeight.normal));;
  }
}


